{% extends "layouts/base.html" %}

{% block title %} 设备类型表 {% endblock %}

<!-- Specific CSS goes HERE -->
{% block stylesheets %}{% endblock stylesheets %}

{% block content %}	

    <!-- [ Main Content ] start -->
    <section class="pcoded-main-container">
        <div class="pcoded-content">
            <!-- [ breadcrumb ] start -->
            <div class="page-header">
                <div class="page-block">
                    <div class="row align-items-center">
                        <div class="col-md-12">
                            <div class="page-header-title">
                                <h5 class="m-b-10">设备类型表</h5>
                            </div>
                            <ul class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{% url 'index' %}"><i class="feather icon-home"></i></a></li>
                                <li class="breadcrumb-item"><a href="#!">基础数据</a></li>
                                <li class="breadcrumb-item"><a href="#!">设备类型表</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <!-- [ breadcrumb ] end -->
            <!-- [ Main Content ] start -->
            <div class = "row">

                <!-- [ stiped-table ] start -->
                <div class = "col-xl-12">

                    <div class = "card">
                        <div class = "card-header">
                            <a href = "{% url 'add_device_type' %}" class = "btn btn-primary"><i
                                    class = "feather mr-2 icon-plus"></i>增加
                            </a>
                        </div>
                        <div class = "card-body table-border-style">
                            <div class = "table-responsive">
                                <table class = "table table-striped table-bordered text-center">
                                    <thead class = "thead-light">
                                        <tr>
                                            <th>序号</th>
                                            <th>类型</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for d in all_devicetype %}
                                            <tr>
                                                <td>{{ forloop.counter }}</td>
                                                <td>{{ d.typename }}</td>
                                                <td>
{#                                                    <a href = "{% url 'view_process_detail' p.id %}"#}
{#                                                       class = "btn btn-sm btn-info"><i#}
{#                                                            class = "feather mr-2 icon-info"></i>详情#}
{#                                                    </a>#}
                                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                                    <button type = "button" class = "btn btn-sm btn-danger"
                                                            data-toggle="tooltip" title="删除只是把类型状态设置为不使用"
                                                            onclick="del_devicetype({{ d.id }})">
                                                        <i class = "feather mr-2 icon-trash-2"></i>删除
                                                    </button>
                                                </td>
                                            </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- [ stiped-table ] end -->
                <script>
                    function del_devicetype(dId) {
                        var r = confirm("你确定要删除吗？")
                        if (r) {
                            $.ajaxSetup({   //获取到cookie中的csrf_token,将其添加到ajax的请求头中,防止出现错误（Forbidden."CSRF token missing or incorrect"）
                                data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
                            })
                            $.ajax({
                                url: "{% url 'del_device_type' %}",
                                type: "post",
                                data: {"id": dId},
                                success: function (arg) {
                                    //alert("此记录已经被删除成功.")
                                    //swal("删除成功", "此记录已经被删除成功.", "success");
                                    window.location.reload()
                                    //$trEle.remove() //在页面上删除已经被删除的那行表格
                                },
                            })
                        }
                    }
                </script>
            </div>
            <!-- [ Main Content ] end -->
        </div>
    </section>
    <!-- [ Main Content ] end -->

{% endblock content %}

<!-- Specific Page JS goes HERE  -->
{% block javascripts %}{% endblock javascripts %}
